# -*- coding: utf-8 -*-
from PySide2 import QtWidgets 
import maya.cmds as mc
import os
import DH_PySideUidata
import shutil


filepath = str(os.path.split(os.path.realpath(__file__))[0])
form_class, base_class = DH_PySideUidata.loadUiType(filepath+'/initializeFile.ui')



class loadselectUI(base_class, form_class):
    def __init__(self):
        self.window_name = 'initializeFile_window'
        if mc.window(self.window_name, exists=True):
            mc.deleteUI(self.window_name)
        super(loadselectUI, self).__init__(parent=DH_PySideUidata.getMayaWindow())
        self.setupUi(self)
        desktop = QtWidgets.QApplication.desktop().availableGeometry()
        size = self.geometry()
        self.move((desktop.width()-size.width())/2, (desktop.height()-size.height())/2)
        
        self.selectProjectMenu.currentTextChanged.connect(self.selectProject)
        self.pushButton_2.clicked.connect(self.inputPath)
        self.pushButton.clicked.connect(self.initializeFile_doit)
        
        
    def selectProject(self):
        whichProject = str(self.selectProjectMenu.currentText())
        #print whichProject
        if whichProject == 'Phoenix':

            self.lineEdit_2.setText('PH_SCXXXSTXXX_Layout_V001')   


        elif whichProject == 'ZSZR':

            self.lineEdit_2.setText('EXXSHXXX_SCXXX_layout_v001')


        elif whichProject == 'XCM':


            self.lineEdit_2.setText('XCM_2019DY_seqXXX_scXXX_an(101-XXX)')

  
               
    def inputPath(self):
        file_path = str(mc.fileDialog2(dialogStyle=1,fm=3))
        filePath = file_path.split('\'')[1]
        self.lineEdit.setText(filePath.encode('utf8'))
                
    def initializeFile_doit(self):
        whichProject = str(self.selectProjectMenu.currentText())
        currentFileName = self.lineEdit_2.text()
        if whichProject == 'Phoenix':
            fileName = 'PH_SCXXXSTXXX_Layout_V001'
        elif whichProject == 'ZSZR':
            fileName = 'EXXSHXXX_SCXXX_layout_v001'
        elif whichProject == 'XCM':
            fileName = 'XCM_2019DY_seqXXX_scXXX_an(101-XXX)'
        filePath = self.lineEdit.text()
        if filePath == '':
            mc.confirmDialog(t='warning',m='��������·��',button='ok')
        servFilePath = 'Y:\OldFile\X_Projects\DHTool\ma\MagicInitialFile'
        shutil.copyfile(servFilePath+'\\'+fileName+'.ma',filePath+'\\'+fileName+'.ma')
        os.rename(filePath+'\\'+fileName+'.ma',filePath+'\\'+currentFileName+'.ma')
        mc.file(filePath+'\\'+currentFileName+'.ma',open=True,f=True,options = 'v=0;',ignoreVersion = True,typ = 'mayaAscii')
        mc.deleteUI(self.window_name)
        mc.confirmDialog(t='warning',m='��ʼ���ɹ���',button='ok')

        
      
        
        
        
        
        
       
        
